import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/**
* hidden: true                   if `hidden:true` 不会在侧边栏显示
* alwaysShow: true               将始终显示根菜单，无论它的子路径长度是多少 如果不设置总路线，只在孩子们下面多走一条路线
*                                it will becomes nested mode, otherwise not show the root menu
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
  }
**/

export const constantRouterMap = [
  { name: 'Login', path: '/login', component: () => import(`@/pages/pc/views/login/index`) },
  {
    path: '/',
    redirect: '/web'
  },
  {
    path: '/web',
    name: 'Web',
    component: () => import('@/pages/pc/views/web/index'),
    redirect: '/web/home',
    children: [
      {
        path: 'home',
        name: 'WebHome',
        meta: { index: 'home' },
        component: () => import('@/pages/pc/views/web/home/index')
      },
      {
        path: 'resume',
        name: 'WebResume',
        meta: { index: 'resume' },
        component: () => import('@/pages/pc/views/web/resume/index')
      },
      {
        path: 'conclusion',
        name: 'WebConclusion',
        meta: { index: 'conclusion' },
        component: () => import('@/pages/pc/views/web/conclusion/index')
      },
      {
        path: 'conclusion/detail',
        name: 'WebConclusionDetail',
        meta: { index: 'conclusion' },
        component: () => import('@/pages/pc/views/web/conclusion/detail')
      },
      {
        path: 'works',
        name: 'WebWorks',
        meta: { index: 'works' },
        component: () => import('@/pages/pc/views/web/works/index')
      },
      {
        path: 'works/detail',
        name: 'WebWorksDetail',
        meta: { index: 'works' },
        component: () => import(`@/pages/pc/views/web/works/detail`)
      },
      {
        path: 'package',
        name: 'WebPackage',
        meta: { index: 'package' },
        component: () => import(`@/pages/pc/views/web/package/index`)
      },
      {
        path: 'package/detail',
        name: 'WebPackageDetail',
        meta: { index: 'package' },
        component: () => import(`@/pages/pc/views/web/package/detail`)
      },
      {
        path: 'opinion',
        name: 'WebOpinion',
        meta: { index: 'opinion' },
        component: () => import(`@/pages/pc/views/web/opinion/index`)
      },
      {
        path: 'tool',
        name: 'WebTool',
        meta: { index: 'tool' },
        component: () => import(`@/pages/pc/views/web/tool/index`)
      }
    ]
  },
  {
    path: '/admin',
    component: () => import(`@/pages/pc/views/admin/layout/index`),
    redirect: '/admin/dashboard',
    name: 'Admin',
    meta: { auth: 'admin', title: '后台管理' },
    children: [
      {
        path: 'dashboard',
        name: 'AdminDashboard',
        meta: { auth: 'admin', hidden: true, title: '后台管理' },
        component: () => import(`@/pages/pc/views/admin/dashboard/index`)
      },
      {
        path: 'web',
        name: 'AdminWeb',
        redirect: '/admin/web/banner',
        component: () => import(`@/pages/pc/views/admin/web/index`),
        meta: { auth: 'admin', title: '网站数据' },
        children: [
          {
            path: 'banner',
            name: 'AdminWebBanner',
            component: () => import(`@/pages/pc/views/admin/web/banner/index`),
            meta: { auth: 'admin', title: 'Banner' }
          },
          {
            path: 'home-links',
            name: 'AdminWebHomeLinks',
            component: () => import(`@/pages/pc/views/admin/web/homeLinks/index`),
            meta: { auth: 'admin', title: 'HomeLinks' }
          },
          {
            path: 'study-time-line',
            name: 'AdminWebStudyTimeLine',
            component: () => import(`@/pages/pc/views/admin/web/studyTimeLine/index`),
            meta: { auth: 'admin', title: '学习时间轴' }
          },
          {
            path: 'experience',
            name: 'AdminWebExperience',
            component: () => import(`@/pages/pc/views/admin/web/experience/index`),
            meta: { auth: 'admin', title: '工作经历' }
          },
          {
            path: 'conclusion',
            name: 'AdminWebConclusion',
            component: () => import(`@/pages/pc/views/admin/web/conclusion/index`),
            redirect: '/admin/web/conclusion/add',
            meta: { auth: 'admin', title: '学习总结' },
            children: [
              {
                path: 'add',
                name: 'AdminWebConclusionAdd',
                component: () => import(`@/pages/pc/views/admin/web/conclusion/add`),
                meta: { auth: 'admin', title: '添加、编辑' }
              },
              {
                path: 'list',
                name: 'AdminWebConclusionList',
                component: () => import(`@/pages/pc/views/admin/web/conclusion/list`),
                meta: { auth: 'admin', title: '列表' }
              }
            ]
          },
          {
            path: 'me',
            name: 'AdminWebMe',
            component: () => import(`@/pages/pc/views/admin/web/me/index`),
            meta: { auth: 'admin', title: '个人数据' }
          },
          {
            path: 'opinion',
            name: 'AdminWebOpinion',
            component: () => import(`@/pages/pc/views/admin/web/opinion/index`),
            meta: { auth: 'admin', title: '意见、建议' }
          },
          {
            path: 'works',
            name: 'AdminWebWorks',
            component: () => import(`@/pages/pc/views/admin/web/works/index`),
            meta: { auth: 'admin', title: '作品' },
            redirect: '/admin/web/works/add',
            children: [
              {
                path: 'add',
                name: 'AdminWebWorksAdd',
                component: () => import(`@/pages/pc/views/admin/web/works/add`),
                meta: { auth: 'admin', title: '添加、编辑' }
              },
              {
                path: 'list',
                name: 'AdminWebWorksList',
                component: () => import(`@/pages/pc/views/admin/web/works/list`),
                meta: { auth: 'admin', title: '列表' }
              }
            ]
          },
          {
            path: 'package',
            name: 'AdminWebPackage',
            component: () => import(`@/pages/pc/views/admin/web/package/index`),
            meta: { auth: 'admin', title: '封装' },
            redirect: '/admin/web/package/add',
            children: [
              {
                path: 'add',
                name: 'AdminWebPackageAdd',
                component: () => import(`@/pages/pc/views/admin/web/package/add`),
                meta: { auth: 'admin', title: '添加、编辑' }
              },
              {
                path: 'list',
                name: 'AdminWebPackageList',
                component: () => import(`@/pages/pc/views/admin/web/package/list`),
                meta: { auth: 'admin', title: '列表' }
              }
            ]
          }
        ]
      },
      {
        path: 'server',
        name: 'AdminServer',
        redirect: '/admin/server/ecs',
        component: () => import(`@/pages/pc/views/admin/web/index`),
        meta: { auth: 'admin', title: 'Server' },
        children: [
          {
            path: 'ecs',
            name: 'AdminServerEcs',
            component: () => import(`@/pages/pc/views/admin/server/ecs/index`),
            meta: { auth: 'admin', title: 'ECS' }
          },
          {
            path: 'oss',
            name: 'AdminServerOss',
            component: () => import(`@/pages/pc/views/admin/server/oss/index`),
            meta: { auth: 'admin', title: 'OSS' }
          }
        ]
      },
      {
        path: 'resources',
        name: 'AdminResources',
        redirect: '/admin/resources/photo',
        component: () => import(`@/pages/pc/views/admin/resources/index`),
        meta: { auth: 'admin', title: '相册' },
        children: [
          {
            path: 'photo',
            name: 'AdminResourcesPhoto',
            component: () => import(`@/pages/pc/views/admin/resources/photo/index`),
            meta: { auth: 'admin', title: '照片' }
          },
          {
            path: 'video',
            name: 'AdminResourcesVideo',
            component: () => import(`@/pages/pc/views/admin/resources/video/index`),
            meta: { auth: 'admin', title: '视频' }
          }
        ]
      },
      {
        path: 'account',
        name: 'AdminAccount',
        redirect: '/admin/account/administrator',
        component: () => import(`@/pages/pc/views/admin/web/index`),
        meta: { auth: 'admin', title: '账号管理' },
        children: [
          {
            path: 'administrator',
            name: 'AdminAccountAdministrator',
            component: () => import(`@/pages/pc/views/admin/account/administrator/index`),
            meta: { auth: 'admin', title: '管理员' }
          }
        ]
      },
      {
        path: 'dustbin',
        name: 'AdminDustbin',
        redirect: '/admin/dustbin/banner',
        component: () => import(`@/pages/pc/views/admin/dustbin/index`),
        meta: { auth: 'admin', title: '回收站' },
        children: [
          {
            path: 'banner',
            name: 'AdminDustbinBanner',
            component: () => import(`@/pages/pc/views/admin/dustbin/banner/index`),
            meta: { auth: 'admin', title: 'Banner' }
          },
          {
            path: 'feedback',
            name: 'AdminDustbinFeedback',
            component: () => import(`@/pages/pc/views/admin/dustbin/feedback/index`),
            meta: { auth: 'admin', title: '意见反馈' }
          },
          {
            path: 'study-time-line',
            name: 'AdminDustbinStudyTimeLine',
            component: () => import(`@/pages/pc/views/admin/dustbin/studyTimeLine/index`),
            meta: { auth: 'admin', title: '学习时间轴' }
          },
          {
            path: 'home-links',
            name: 'AdminDustbinHomeLinks',
            component: () => import(`@/pages/pc/views/admin/dustbin/homeLinks/index`),
            meta: { auth: 'admin', title: 'HomeLinks' }
          },
          {
            path: 'package',
            name: 'AdminDustbinPackage',
            component: () => import(`@/pages/pc/views/admin/dustbin/package/index`),
            meta: { auth: 'admin', title: '封装' }
          },
          {
            path: 'product',
            name: 'AdminDustbinProduct',
            component: () => import(`@/pages/pc/views/admin/dustbin/product/index`),
            meta: { auth: 'admin', title: '作品' }
          },
          {
            path: 'study',
            name: 'AdminDustbinStudy',
            component: () => import(`@/pages/pc/views/admin/dustbin/study/index`),
            meta: { auth: 'admin', title: '学子总结' }
          },
          {
            path: 'work',
            name: 'AdminDustbinWork',
            component: () => import(`@/pages/pc/views/admin/dustbin/work/index`),
            meta: { auth: 'admin', title: '工作经历' }
          }
        ]
      },
      {
        path: 'logs',
        name: 'AdminLogs',
        redirect: '/admin/logs/web',
        component: () => import(`@/pages/pc/views/admin/logs/index`),
        meta: { auth: 'admin', title: '日志' },
        children: [
          {
            path: 'web',
            name: 'AdminLogsWeb',
            component: () => import(`@/pages/pc/views/admin/logs/web/index`),
            meta: { auth: 'admin', title: '网站' },
            redirect: '/admin/logs/web/process',
            children: [
              {
                path: 'process',
                name: 'AdminLogsWebProcess',
                component: () => import(`@/pages/pc/views/admin/logs/web/process/index`),
                meta: { auth: 'admin', title: '流程' }
              },
              {
                path: 'ajax',
                name: 'AdminLogsWebAjax',
                component: () => import(`@/pages/pc/views/admin/logs/web/ajax/index`),
                meta: { auth: 'admin', title: 'Ajax' }
              },
              {
                path: 'Error',
                name: 'AdminLogsWebError',
                component: () => import(`@/pages/pc/views/admin/logs/web/error/index`),
                meta: { auth: 'admin', title: '错误' }
              }
            ]
          },
          {
            path: 'server',
            name: 'AdminLogsServer',
            component: () => import(`@/pages/pc/views/admin/logs/server/index`),
            meta: { auth: 'admin', title: '服务器' },
            redirect: '/admin/logs/server/process',
            children: [
              {
                path: 'process',
                name: 'AdminLogsServerProcess',
                component: () => import(`@/pages/pc/views/admin/logs/server/process/index`),
                meta: { auth: 'admin', title: '流程' }
              },
              {
                path: 'Error',
                name: 'AdminLogsServerError',
                component: () => import(`@/pages/pc/views/admin/logs/server/error/index`),
                meta: { auth: 'admin', title: '错误' }
              }
            ]
          }
        ]
      },
    ]
  },
  // 如果找不到就显示404界面
  { path: '*', redirect: '/', hidden: true }
]

const router = new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

router.beforeEach((to, from, next) => {
  next()
})

export default router
